<?php

require dirname(__FILE__) . "/../classes/imageClass.php";
require dirname(__FILE__) . "/../classes/albumClass.php";
require dirname(__FILE__) . "/../classes/connectionFactoryClass.php";
require dirname(__FILE__) . "/../classes/imageDao.php";
require dirname(__FILE__) . "/../classes/albumDao.php";
require dirname(__FILE__) . "/../classes/validates.php";



$image = new ImageClass();
$c = new ConnectionFactory();
$db = $c->getConnection();
$imageDao = new imageDao($db);
$albumDao = new albumDao($db);
$valid = new validates();

//buscando albuns
$albuns = $albumDao->getAlbuns('');
if ($albuns) {
    foreach ($albuns as $a) {
        $dir = '../' . $a->getDirectory() .$a->getNameUser().'/'. $a->getNameAlbum();
        
//deleletando fotos existentes no album
        foreach (scandir($dir) as $item) {
            if ($item == '.' || $item == '..')
                continue;
            unlink($dir . DIRECTORY_SEPARATOR . $item);
        }
        
//deleta o album
        rmdir($dir);
    }

if ($imageDao->removeAll()) {
    if ($albumDao->removeAll()) {
        echo"<script> alert('Todas as fotos foram deletadas.'); 
          window.location='../index.php';</script>";
    }echo"<script> alert('Não foi possível deletar.'); 
          window.location='../index.php';</script>";
}
else
    echo"<script> alert('Não foi possível deletar.'); 
          window.location='../index.php';</script>";

$user=$a->getDirectory().$a->getNameUser();
 rmdir($user);
    }else
    echo"<script> alert('Não existe registros.'); 
          window.location='../index.php';</script>";
?>

